﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_AttoneyAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {  System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        { }

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            HZ.MBSM.Model.Attorney Attorney = new HZ.MBSM.Model.Attorney();
            HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();

            int i = 0, rowCun = 0;
            if (Attorney != null)
            {
                Db db = new Db();
                System.Data.IDataReader dr;
                string strSql = "select count(accountid) as cun from dbo.v_account where accountname='" + SysFun.ToTrim(AccountName.Text) + "'  or dwname= '" + SysFun.ToTrim(AttorneyName.Text) + "' or usercode='" + SysFun.ToTrim(txtUserCode.Text) + "'";
                dr = db.DataReader(strSql);
                if (dr.Read())
                {
                    rowCun = SysFun.ToInt(dr["cun"]);
                }
                dr.Close();
                dr.Dispose();
                db.Close();
                if (rowCun > 0)
                {
                    Response.Write("<script language=JavaScript>alert('该用户在数据库中已经存在！！！');</script>");
                }
                else
                {

                    Account.AccountName = SysFun.ToTrim(AccountName.Text);
                    Account.Pwd_Bid = SysFun.PasswordEncrypt(SysFun.ToTrim(Pwd_Bid.Text));
                    Account.Pwd_Trade = SysFun.PasswordEncrypt(SysFun.ToTrim(Pwd_Bid.Text));
                    Account.Type = Convert.ToUInt16(HZ.MBSM.DAL.AccountType.enumAttorney).ToString();
                    Account.IsBid_Landing = "1";
                    Attorney.AttorneyName = SysFun.ToTrim(AttorneyName.Text);                    
                    Attorney.Address = Address.Text;
                    Attorney.AreaId = SysFun.ToInt(Request.Form["AreaId"]);// Convert.ToInt16(AreaId.Text);
                    Attorney.Bank = SysFun.ToTrim(Bank.Text);
                    Attorney.Email = SysFun.ToTrim(Email.Text);
                    Attorney.EmployeeNum = SysFun.ToInt(EmployeeNum.Text);
                    Attorney.Fax = SysFun.ToTrim(Fax.Text);
                    if (FoundDate.Text.ToString() != "")
                    {
                        Attorney.FoundDate = Convert.ToDateTime(FoundDate.Text);
                    }
                    else
                    {
                        Attorney.FoundDate = Convert.ToDateTime("1900-1-1");
                    }
                    Attorney.Fund = SysFun.ToInt(Fund.Text);
                    Attorney.Lawer = SysFun.ToTrim(Lawer.Text);
                    Attorney.NationalCmp = SysFun.ToTrim(NationalCmp.Text);
                    Attorney.NetAddress = SysFun.ToTrim(NetAddress.Text);
                    Attorney.PostCode = SysFun.ToTrim(PostCode.Text);
                    Attorney.registDate = System.DateTime.Now;
                    Attorney.Telephone = Telephone.Text;
                    Attorney.UserCode = txtUserCode.Text.ToString();
                    i = HZ.MBSM.BLL.UserRegist.RegistAttoney(Account, Attorney);
                    HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "添加", "Account,Attorney", "HZ.MBSM.BLL.UserRegist.RegistAttoney(Account, Attorney)", "../Magage/AttoneyAdd.aspx");

                    Response.Write("<script>alert('保存成功！！！');</script>");
                    Response.Write("<script>window.opener.location.reload();window.close();</script>");
                }
            }
        }
    }
 
}
